﻿#define _CRT_SECURE_NO_WARNINGS 1
#pragma warning(disable:6031)

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<time.h>
int mystrcat(char* str1, char* str2)
{
	int i = 0;
	while (*(str1+i) != '\0')
	{
		i++;
	}
	int j = 0;
	while (*(str2 + j) != '\0')
	{
		*(str1 + i + j) = *(str2 + j);
		j++;
	}
	*(str1 + i + j) = '\0';
	return str1;
}
void show1()
{
	printf("**************************\n");
	printf("**********  w l x  *********\n");
	
}
void show2()
{
	printf("**********  love  ********\n");
}
void show3()
{
	
	printf("********* 温龙鑫 *********\n");
	printf("**************************\n");
}
void text(void(*p)(void))
{
	(*p)();
}
int add(int a, int b)
{
	return a + b;
}
int dis(int a, int b)
{
	return a - b;
}
void test(int (*p)(int, int))
{
	int res = p(20, 10);
	printf("%d",res);
}

//void test(int(*p)[3], int r, int c)
//{
//	int i, j;
//	for (i = 0; i < r; i++)
//	{
//		for (j = 0; j < c; j++)
//		{
//			scanf("%d", *(p + i) + j);
//		}
//	}
//	for (i = 0; i < r; i++)
//	{
//		for (j = 0; j < c; j++)
//		{
//			printf("%d ", *(*(p + i) + j));
//		}
//		printf("\n");
//	}
//}
//int command(char(*p1)[30], char* p2)
//{
//	int i;
//	for (i = 0; i < 10; i++)
//	{
//		if (strcmp(*(p1 + i), p2) == 0)
//		{
//			return 1;
//		}
//
//	}
//		return 0;
//}
int main()
{
	//数组指针 指向对象的类型 *指针变量[元素个数]
	/*char s[][20] = { "lili","tom","timi" };
	char(*p)[20] = s;
	printf("%s\n", *(p + 0));//%s输出直接给地址即可
	printf("%p\n", *(p + 0));
	printf("%p\n", *(p + 0) + 0);
	printf("%c\n", *(*(p + 0) + 0));
	printf("%c\n", *(*(p + 0) + 1));
	printf("%c\n", *(*(p + 0) + 2));
	printf("%c\n", *(*(p + 0) + 3));*/
	
	/*int arr[3][3] = { {1,2,3},{2,3,4},{3,4,5} };
	int(*p)[3] = arr;
	printf("%p\n", *(p + 0) + 0);
	printf("%p\n", *(p));
	printf("%p\n", *(p + 0) + 1);
	printf("%d\n", *(*(p + 0) + 0));
	printf("%d\n", *(*(p + 0) + 1));*/

	//将二维数组传入到函数中取得时候，二维数组做函数的参数，对应的形参应该设计成数组指针。
	/*int arr[3][3];
	int(*p)[3] = arr;
	int i, j;
	for (i = 0; i < 3; i++)
	{
		for (j = 0; j < 3; j++)
		{
			scanf("%d", *(p + i) + j);
		}
	}
	for (i = 0; i < 3; i++)
	{
		for (j = 0; j < 3; j++)
		{
			printf("%d ", *(*(p + i) + j));
		}
		printf("\n");
	}*/
	//用数组指针传参的方式打印二维数组    ⼆维数组传参的本质
	//int a[4][3];
	//int row = sizeof(a)/sizeof(a[0]);
	//int col = sizeof(a[0]) / sizeof(a[0][0]);
	//test(a, row, col);

	/*主函数有一个指令包, 指令包里有10个字符串指令
		用户再输入一个字符串指令,
		写一个子函数, 判断用户输入的字符串指令是否在指令包中,
		如果在指令包中返回1, 不在指令包中返回0;*/
	//char str1[10][30] = { "wwe","wwr","wwt","wwy","wwu","wwi","wwo","wwp","wwa","wws" };
	//char str2[30];
	//printf("请输入输入一个字符串指令：");
	//scanf("%s",str2);
	//int c = command(str1, str2);
	//printf("%d",c);
	

	








	//指针数组	指针类型 *数组名[元素个数]
	/*int a = 10;
	int b = 20;
	 
	int* arr[2];

	arr[0] = &a;
	arr[1] = &b;
	printf("%d %d\n",*(arr[0]),*(arr[1]));
	*arr[0] = 20;
	*arr[1] = 10;
	printf("%d %d", *(arr[0]), *(arr[1]));*/

	//练习：
	/*char s1[] = "hello";
	char s2[] = "world";
	char s3[] = "xiaoming";
	定义一个指针数组，存储每一个字符串首字符的地址，然后通过指针数组名操作对应的字符串。*/
	//char s1[] = "hello";
	//char s2[] = "world";
	//char s3[] = "xiaoming";
	//char* p[3];
	//p[0] = s1;
	//p[1] = s2;
	//p[2] = s3;
	////输出首字符
	//printf("%c\n", *(p[0]));
	//printf("%c\n", *(p[1]));
	//printf("%c\n", *(p[2]));
	////输出字符串
	//printf("%s\n", p[0]);//%s输出直接给地址即可
	//printf("%s\n", p[1]);
	//printf("%s\n", p[2]);
	

	//使用指针数组存储下列字符串然后设计抽奖程序。
	//char s1[] = "xiaoming";
	//char s2[] = "xiaolan";
	//char s3[] = "xiaohei";
	//char s4[] = "xiaobai";
	//char s5[] = "xiaoyanzi";
	//char s6[] = "xiaohuamao";
	//char s7[] = "xiaotu";
	//char s8[] = "xiaomei";
	//char* p[8] = {s1,s2,s3,s4,s5,s6,s7,s8};
	//srand((unsigned int)time(NULL));
	//int count = rand() % 8;//范围：0~8
	//printf("中奖的人是：");
	//printf("%s",p[count]);

	//指针数组模拟⼆维数组
	//int arr1[] = { 1,2,3,4,5 };
	//int arr2[] = { 2,3,4,5,6 };
	//int arr3[] = { 3,4,5,6,7 };
	//int* p[3] = { arr1,arr2,arr3 };
	//for (int i = 0; i < 3; i++)
	//{
	//	for (int j = 0; j < 3; j++)
	//	{
	//		printf("%d ", *(*(p + i) + j));
	//		//printf("%d ", p[i][j]);
	//	}
	//	printf("\n");
	//}
												










		//函数指针
	/*void (*p)(void) = show;
	int (*q)(int,int) = add;
	(*p)();
	p();
	printf("%d ", q(3, 5));
	printf("%d",(*q)(3,5));*/
	/*test(add);
	printf("\n");
	test(dis);
	printf("\n");
	text(show1);
	text(show2);
	text(show3);*/
	//unsigned char a, b, c, d, e, f, g, h, x, y, z;
	//unsigned char niu[6] = { 3,6,10,21,40,50 };
	//unsigned char* sp;
	//sp = niu;
	//a = *sp;         // 3
	//b = *sp + 1;    // 4
	//c = *(sp + 1);   // 6
	//d = *sp++;      //*(sp++)    3  sp->niu[1]
	//e = *sp;  //6
	//x = sizeof(niu); // 6
	//y = sizeof(sp);  // 4 / 8
	//z = sizeof(*sp);  // 1
	//printf("%d %d %d %d %d %d %d %d",a,b,c,d,e,x,y,z);










		//指针函数使用：
	/*char s1[30] = { "Hello" };
	char s2[] = {"world"};
	char* p = mystrcat(s1, s2);
	printf("%p\n", p);
	printf("%s",p);*/

	








	//二级指针的使用
	//int a = 10;
	//int b = 20;
	//int* p = &a;//p指向a
	//printf("%d\n",*p);
	//int** q = &p;//q指向p
	//printf("%d\n", **q);
	////通过二级指针q将p的指向指向b.  *q==p的空间
	//*q = &b;
	//printf("%d\n", *p);



}